<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('库存管理列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input id="treeId" name="deptId" type="hidden"/>
                <input id="thingTypeId"  name="thingTypeId" type="hidden"/>
                <input id="categoryTreeId" name="params[thingId]" type="hidden"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label>行名称：</label>
                            <input readonly="readonly" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属行">
                        </li>
                        <li>
                            <label>物品目录：</label>
                            <input readonly="readonly" onclick="selectCategoryTree()" id="categoryTreeName" type="text"
                                   placeholder="请选择物品分类">
                        </li>
                        <li>
                            <label >物品名称：</label>
                            <input type="text" name="createName"/>
                        </li>
                        <li>
                            <label>物品信息：</label>
                            <input type="text" name="mohu"/>
                        </li>
                        <li>
                            <label>收支项目：</label>
                            <input readonly="readonly" onclick="selectThingTypeTree()" id="thingType" type="text" placeholder="请选择收支项目" >
                        </li>

                        <li class="select-time">
                            <label>时间范围： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="chongzhi()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="financial:fEnter:kucunexport">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var myDeptId = [[${myDeptId}]]

    var addFlag = [[${@permission.hasPermi('financial:fOutbound:add')}]];
    var thingTypeDatas = [[${@dict.getType('f_thing_type')}]];
    var prefix = ctx + "financial/fEnter";

    $(function () {
        var options = {
            url: prefix + "/kucunList",
            createUrl: ctx + "/financial/fOutbound/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/kucunexport",
            detailUrl: prefix + "/detail/{id}",
            modalName: "库存列表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'thingId',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'deptName',
                    title: '行名称',
                },
                {
                    field: 'thingName',
                    title: '物品目录',
                },
                {
                    field: 'thingType',
                    title: '收支项目'
                },
                {
                    field: 'createName',
                    title: '物品名称',
                },
                {
                    field: 'mohu',
                    title: '物品信息',
                },
                {
                    field: 'shuliang',
                    title: '入库数量',
                },
                {
                    field: 'zonge',
                    title: '总额',
                },
                {
                    field: 'averageDanjia',
                    title: '平均价格',
                },
                {
                    field: 'chushuliang',
                    title: '出库数量',
                },
                {
                    field: 'renjunxiaohao',
                    title: '人均消耗',
                },
                {
                    field: 'kucunshuliang',
                    title: '库存',
                },
                {
                    title: '操作',
                    align: 'center',
                    width:130,
                    formatter: function (value, row, index) {
                        var actions = [];
                        if(myDeptId == row.deptId){
                            actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="openchuku(' + row.enterId +','+row.kucunshuliang+')"><i class="fa fa-plus"></i>出库</a> ');
                            actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="shiyongDetail(' + row.thingId +','+row.deptId + ',' +row.enterId+')"><i class="fa fa-search"></i>详细</a> ');
                        }else{
                            actions.push('<a class="btn btn-warning btn-xs " style="margin-left: 50px" href="javascript:void(0)" onclick="shiyongDetail(' + row.thingId +','+row.deptId + ',' +row.enterId+')"><i class="fa fa-search"></i>详细</a> ');
                        }

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择行',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectCategoryTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/fThing/selectFThingCategoryTree/";
        var options = {
            title: '选择物品',
            width: "380",
            url: url,
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#categoryTreeId").val(body.find('#treeId').val());
        $("#categoryTreeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectThingTypeTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/thingType/selectThingTypeTree/";
        var options = {
            title: '选择收支项目',
            width: "380",
            url: url,
            callBack: doSubmit3
        };
        $.modal.openOptions(options);
    }
    function doSubmit3(index, layero){
        var body = $.modal.getChildFrame(index);
        $("#thingTypeId").val(body.find('#treeId').val());
        $("#thingType").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function chongzhi() {
        $("#treeId").val("")
        $("#categoryTreeId").val("")
        $("#thingType").val("")
        $("#thingTypeId").val("")
        $.form.reset()
    }

    function shiyongDetail(thingId,deptId,enterId) {
        var postId = 0;
        if ($("#postId").val()) {
            postId = $("#postId").val()
        }
        $.modal.openOptions({
            title: "详细",
            url: ctx + "financial/fOutbound/kucunDetail/" + deptId + "/" + postId + "/" + thingId +"/"+enterId,
            btn: 0
        });
    }

    function openchuku(enterId,kuncunSize) {
        if(parseInt(kuncunSize) <= 0){
            $.modal.alertWarning('库存不足！')
            return
        }
        $.modal.open("出库", ctx + "financial/fOutbound/add?enterId="+enterId+"&kuncunSize="+kuncunSize);
    }


</script>
</body>
</html>